﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using TallyBook.BLL.Service.Imp;
using TallyBook.UI.Properties;

namespace TallyBook.UI
{
    public partial class MainForm : Form
    {
        private readonly List<Button> _buttons = new List<Button>();
        private readonly List<Button> _listbButtons = new List<Button>();

        public MainForm()
        {
            InitializeComponent();
            tssTime.Text = DateTime.Now.ToLongDateString();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            _buttons.Add(btnEverydayWork1);
            _buttons.Add(btnOWork1);
            _buttons.Add(btnComWork1);
            _buttons.Add(btnEverydayWork2);
            _buttons.Add(btnOWork2);
            _buttons.Add(btnComWork2);
            _buttons.Add(btnSystem2);
            _buttons.Add(btnSystem1);
            _listbButtons.Add(btnChange1);
            _listbButtons.Add(btnChange2);
            _listbButtons.Add(btnChange3);
            Together_Click(btnEverydayWork1, null);
        }

        /// <summary>
        ///     button控件隐藏显示的实现
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Together_Click(object sender, EventArgs e)
        {
            _buttons.ForEach(item => item.Visible = true);
            var currentButton = (Button) sender;
            if (currentButton.Name.Contains("btnEverydayWork"))
            {
                btnComWork1.Hide();
                btnSystem1.Hide();
                btnOWork1.Hide();
                btnEverydayWork2.Hide();
            }
            if (currentButton.Name.Contains("btnOWork"))
            {
                btnComWork1.Hide();
                btnSystem1.Hide();
                btnEverydayWork2.Hide();
                btnOWork2.Hide();
            }
            if (currentButton.Name.Contains("btnComWork"))
            {
                btnSystem1.Hide();
                btnEverydayWork2.Hide();
                btnComWork2.Hide();
                btnOWork2.Hide();
            }
            if (currentButton.Name.Contains("btnSystem"))
            {
                btnSystem1.Hide();
                btnEverydayWork2.Hide();
                btnComWork2.Hide();
                btnOWork2.Hide();
            }
            BtnChange(currentButton.Name);
        }

        /// <summary>
        ///     改变button的text的值
        /// </summary>
        /// <param name="btnName"></param>
        private void BtnChange(string btnName)
        {
            _listbButtons.ForEach(item => item.Visible = false);
            switch (btnName.Remove(btnName.Length - 1))
            {
                case "btnEverydayWork":
                    btnChange1.Text = @"账户管理";
                    btnChange2.Text = @"收入管理";
                    btnChange3.Text = @"支出管理";
                    _listbButtons.ForEach(item => item.Visible = true);
                    break;
                case "btnOWork":
                    btnChange1.Text = @"你好";
                    btnChange2.Text = @"你们好";
                    _listbButtons[0].Visible = true;
                    _listbButtons[1].Visible = true;
                    break;
                case "btnComWork":
                    btnChange1.Text = @"企业管理";
                    _listbButtons[0].Visible = true;
                    break;
                case "btnSystem":
                    btnChange1.Text = @"退出";
                    _listbButtons[0].Visible = true;
                    break;
            }
        }

        /// <summary>
        ///     显示对应界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOptionsMenu_Click(object sender, EventArgs e)
        {
            var currentButton = (Button) sender;
            UserControl userControl = null;

            switch (currentButton.Text)
            {
                case "账户管理":
                    userControl = new AccountControl(new AccountService());
                    mainBox.Text = mainBox.Text = Resources.MainAccount;
                    break;

                case "支出管理":

                    userControl = new OutlayControl(new OutlayService());
                    mainBox.Text = mainBox.Text = Resources.MainExpend;
                    break;
                case "收入管理":
                    userControl = new IncomeControl(new IncomeService());
                    mainBox.Text = mainBox.Text = Resources.MainIncome;
                    break;
                case "":
                    break;
            }
            if (userControl == null)
                return;
            mainBox.Controls.Clear();
            userControl.Parent = mainBox;
            userControl.Dock = DockStyle.Fill;
            userControl.Show();
        }
    }
}